#delimit ;
clear all;
set more off;
pause on;


/**************************************************************************************************/
/* ABOUT THIS FILE & RUNNING NOTES */
/**************************************************************************************************/

/*
PUROPSE
Analyzes the poster data using the candidate as the unit of analysis.
Produces the figures and tables for the manuscript and its online supplementary materials.
*/

/**************************************************************************************************/
/* OPEN FILE & MACRO SETUP */
/**************************************************************************************************/

use "dta/db_can.dta";

/* Regression Macros -----------------------------------------------------------------------------*/
local otreg_opt
	bdec(3) sdec(3) rdec(2) symbol(**, *, ^) label;

/* Vars Macros ------------------------------------------------------------------------------------*/

local ivars
	muslim_pop modern_grdp_pct reg_leg;

local cvars
  female_can java jakarta;

/* Chart Macros ----------------------------------------------------------------------------------*/

local marginsplot_baropts
	yscale(range(0 1) noline)
	ylabel(0(.1)1, labsize(3))
  recast(bar)
  plotopts(barw(.7))
	level(90);

local marginsplot_lineopts
	yscale(range(0 1) noline)
	ylabel(0(.1)1, labsize(3))
  plotopts(msize(vsmall))
	level(90);

local cibplot_opts
	baropts(barwidth(2))
  yscale(range(0 1) noline)
	ylabel(0(.1)1, labsize(3))
	yscale(noline)
  level(90);

local gph_combine_opts
	imargin(l=0 r=4 b=10 t=5)
	ycommon
	ysize(14)
	xsize(20)
	plotregion(style(none));


/**************************************************************************************************/
/* Figure 2	The Muslim population and candidates' appeals */
/**************************************************************************************************/

/* Raw Percentage Bar Charts --------------------------------------------------------------------*/

gen muslim_pop_50pc = (muslim_pop >= 0.5);
label variable muslim_pop_50pc "Muslim Pop. (1=50%+)";

graph
	bar (mean) nat_pos,
	over(muslim_pop_50pc, relabel(1 "Min" 2 "Maj") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(All Candidates, size(3.5))
	name(mpop_all_nat, replace);

graph
	bar (mean)
	islam_pos,
	over(muslim_pop_50pc, relabel(1 "Min" 2 "Maj") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(All Candidates, size(3.5))
	name(mpop_all_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 0,
	over(muslim_pop_50pc, relabel(1 "Min" 2 "Maj") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Muslim Democrats, size(3.5))
	name(mpop_md_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 0,
	over(muslim_pop_50pc, relabel(1 "Min" 2 "Maj") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Muslim Democrats, size(3.5))
	name(mpop_md_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 1,
	over(muslim_pop_50pc, relabel(1 "Min" 2 "Maj") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Islamists, size(3.5))
	name(mpop_is_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 1,
	over(muslim_pop_50pc, relabel(1 "Min" 2 "Maj") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Islamists, size(3.5))
	name(mpop_is_is, replace);

graph combine
	mpop_all_nat mpop_all_is mpop_md_nat mpop_md_is mpop_is_nat mpop_is_is,
	`gph_combine_opts' 	rows(1) name(muspop_bar, replace)
	title("% of candidates poster campaigns with Nationalist (grey) & Islamic (black) appeals", size(3.5))
	subtitle("Over Muslim population (minority or majority)", size(3));

graph export "figures/fig_2a.pdf", as(pdf) replace;


/* Predicted Probabilities Line Charts ---------------------------------------------------------*/

reg nat_pos `ivars' `cvars', robust;
margins, at(muslim_pop =(0(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  name(pop_mp1, replace)
  title(Nationalist Appeals, tstyle(size(medium)));

reg nat_pos `ivars' `cvars' if is_party == 0, robust;
margins, at(muslim_pop =(0(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  name(pop_mp2, replace)
  title(MUSLIM DEM: Nationalist Appeals, tstyle(size(medium)));

reg nat_pos `ivars' `cvars' if is_party == 1, robust;
margins, at(muslim_pop =(0(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  name(pop_mp3, replace)
  title(ISLAMISTS: Nationalist Appeals, tstyle(size(medium)));

reg islam_pos `ivars' `cvars', robust;
margins, at(muslim_pop =(0(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  name(pop_mp4, replace)
  title(Islamic Appeals, tstyle(size(medium)));

reg islam_pos `ivars' `cvars' if is_party == 0, robust;
margins, at(muslim_pop =(0(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  name(pop_mp5, replace)
  title(MUSLIM DEM: Islamic Appeals, tstyle(size(medium)));

reg islam_pos `ivars' `cvars' if is_party == 1, robust;
margins, at(muslim_pop =(0(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  name(pop_mp6, replace)
  title(ISLAMISTS: Islamic Appeals, tstyle(size(medium)));

graph combine
	pop_mp1 pop_mp2 pop_mp3 pop_mp4 pop_mp5 pop_mp6,
	`gph_combine_opts' 	rows(2) name(muspop_mp, replace)
	title("Minority to majority Muslim population constituencies", size(4));

graph export "figures/fig_2b.pdf", as(pdf) replace;


/**************************************************************************************************/
/* Figure 3	The district type and candidates' appeals */
/**************************************************************************************************/

/* Raw Percentage Bar Charts --------------------------------------------------------------------*/

gen urban_b = (modern_grdp_pct >= .85);
label variable urban_b "Urban (urban > 85%)"; // (modern GRDP > 85%) with 85% approximatley half candidates are in 'rural' areas. if we use urban 50% the figures are almost identical

graph
	bar (mean) nat_pos,
	over(urban_b, relabel(1 "Rural" 2 "Urban") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(All Candidates, size(3.5))
	name(dis_all_nat, replace);

graph
	bar (mean)
	islam_pos,
	over(urban_b, relabel(1 "Rural" 2 "Urban") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(All Candidates, size(3.5))
	name(dis_all_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 0,
	over(urban_b, relabel(1 "Rural" 2 "Urban") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Muslim Democrats, size(3.5))
	name(dis_md_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 0,
	over(urban_b, relabel(1 "Rural" 2 "Urban") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Muslim Democrats, size(3.5))
	name(dis_md_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 1,
	over(urban_b, relabel(1 "Rural" 2 "Urban") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Islamists, size(3.5))
	name(dis_is_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 1,
	over(urban_b, relabel(1 "Rural" 2 "Urban") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Islamists, size(3.5))
	name(dis_is_is, replace);

graph combine
	dis_all_nat dis_all_is dis_md_nat dis_md_is dis_is_nat dis_is_is,
	`gph_combine_opts' 	rows(1) name(modern_bar, replace)
	title("% of candidates poster campaigns with Nationalist (grey) & Islamic (black) appeals", size(3.5))
	subtitle("Over District Type (rural or urban)", size(3));

graph export "figures/fig_3a.pdf", as(pdf) replace;


/* Predicted Probabilities Line Charts ---------------------------------------------------------*/

reg nat_pos `ivars' `cvars', robust;
margins, at(modern_grdp_pct =(.4(.1)1)) vsquish; // for grdp measure use =(.4(.1)1)) for all
marginsplot, `marginsplot_lineopts'
  title(Nationalist Appeals, tstyle(size(medium)))
  name(modern_mp1, replace);

reg nat_pos `ivars' `cvars' if is_party == 0, robust;
margins, at(modern_grdp_pct =(.4(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(MUSLIM DEM: Nationalist Appeals, tstyle(size(medium)))
  name(modern_mp2, replace);

reg nat_pos `ivars' `cvars' if is_party == 1, robust;
margins, at(modern_grdp_pct =(.4(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(ISLAMISTS: Nationalist Appeals, tstyle(size(medium)))
  name(modern_mp3, replace);

reg islam_pos `ivars' `cvars', robust;
margins, at(modern_grdp_pct =(.4(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(Islamic Appeals, tstyle(size(medium)))
  name(modern_mp4, replace);

reg islam_pos `ivars' `cvars' if is_party == 0, robust;
margins, at(modern_grdp_pct =(.4(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(MUSLIM DEM: Islamic Appeals, tstyle(size(medium)))
  name(modern_mp5, replace);

reg islam_pos `ivars' `cvars' if is_party == 1, robust;
margins, at(modern_grdp_pct =(.4(.1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(ISLAMISTS: Islamic Appeals, tstyle(size(medium)))
  name(modern_mp6, replace);

graph combine
	modern_mp1 modern_mp2 modern_mp3 modern_mp4 modern_mp5 modern_mp6,
	`gph_combine_opts' 	rows(2) name(modern_mp, replace)
	title("Rural to urban constituencies", size(4));

graph export "figures/fig_3b.pdf", as(pdf) replace;

/**************************************************************************************************/
/* Figure 4	National and regional constituency elections and candidates' appeals */
/**************************************************************************************************/

/* Raw Percentage Bar Charts --------------------------------------------------------------------*/

graph
	bar (mean) nat_pos,
	over(reg_leg, relabel(1 "Nat." 2 "Reg.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(All Candidates, size(3.5))
	name(leg_all_nat, replace);

graph
	bar (mean)
	islam_pos,
	over(reg_leg, relabel(1 "Nat." 2 "Reg.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(All Candidates, size(3.5))
	name(leg_all_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 0,
	over(reg_leg, relabel(1 "Nat." 2 "Reg.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Muslim Democrats, size(3.5))
	name(leg_md_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 0,
	over(reg_leg, relabel(1 "Nat." 2 "Reg.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Muslim Democrats, size(3.5))
	name(leg_md_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 1,
	over(reg_leg, relabel(1 "Nat." 2 "Reg.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Islamists, size(3.5))
	name(leg_is_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 1,
	over(reg_leg, relabel(1 "Nat." 2 "Reg.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).6)
	title(Islamists, size(3.5))
	name(leg_is_is, replace);

graph combine
	leg_all_nat leg_all_is leg_md_nat leg_md_is leg_is_nat leg_is_is,
	`gph_combine_opts' 	rows(1) name(elec_bar, replace)
	title("% of candidates poster campaigns with Nationalist (grey) & Islamic (black) appeals", size(3.5))
	subtitle("Over Constituency Type (National election or Regional election)", size(3));

graph export "figures/fig_4a.pdf", as(pdf) replace;


/* Predicted Probabilities Line Charts ---------------------------------------------------------*/

tab election;
reg nat_pos `ivars' `cvars', robust;
margins, at(reg_leg =(0(1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(Nationalist Appeals)
  name(elec_mp1, replace);

reg nat_pos `ivars' `cvars'  if is_party == 0, robust;
margins, at(reg_leg =(0(1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(MUSLIM DEM: Mean Nationalist Appeals)
  name(elec_mp2, replace);

reg nat_pos `ivars' `cvars'  if is_party == 1, robust;
margins, at(reg_leg =(0(1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(ISLAMISTS: Nationalist Appeals)
  name(elec_mp3, replace);

reg islam_pos `ivars' `cvars', robust;
margins, at(reg_leg =(0(1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(Islamic Appeals)
  name(elec_mp4, replace);

reg islam_pos `ivars' `cvars'  if is_party == 0, robust;
margins, at(reg_leg =(0(1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(MUSLIM DEM: Islamic Appeals)
  name(elec_mp5, replace);

reg islam_pos `ivars' `cvars'  if is_party == 1, robust;
margins, at(reg_leg =(0(1)1)) vsquish;
marginsplot, `marginsplot_lineopts'
  title(ISLAMISTS: Islamic Appeals)
  name(elec_mp6, replace);

graph combine
	elec_mp1 elec_mp2 elec_mp3 elec_mp4 elec_mp5 elec_mp6,
	`gph_combine_opts' 	rows(2) name(elec_mp, replace)
	title("National and regional constituencies", size(4));

graph export "figures/fig_4b.pdf", as(pdf) replace;

/**************************************************************************************************/
/* Figure 5	Predicted probabilities of nationalist & Islamic appeals in poster campaigns by party */
/**************************************************************************************************/

tab is_party;
reg nat_pos is_party `ivars' `cvars', robust;
margins, at(is_party =(0(1)1)) vsquish;
marginsplot, `marginsplot_baropts'
  name(party_mp1, replace)
  title(Mean Nationalist Appeals)
  subtitle("Over Candidates (Muslim democrats = 0 Islamists = 1)");

reg islam_pos is_party `ivars' `cvars', robust;
margins, at(is_party =(0(1)1)) vsquish;
marginsplot, `marginsplot_baropts'
  name(party_mp2, replace)
  title(Mean Islamic Appeals)
  subtitle("Over Candidates (Muslim democrats = 0 Islamists = 1)");

graph combine
	party_mp1 party_mp2,
	`gph_combine_opts' 	rows(1) name(party_mp, replace)
	title("Predicted probabilities of appeals by party type (with controls)", size(4));

graph export "figures/fig_5.pdf", as(pdf) replace;

/**************************************************************************************************/
/* Figure 7	Nationalist and Islamic appeals by Islamist parties competing nationally or regionally (only in Aceh) */
/**************************************************************************************************/

preserve;
drop if prov_no != 1100; // Only analyzing candidates in Aceh.

graph
	bar (mean) nat_pos islam_pos if is_party == 0,
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	bar(2, fcolor(black) lcolor(none))
	yscale(off)
	legend(off)
	ylabel(0(.1).8)
	title(Muslim Democrats (national), size(3.5))
	name(md_nat, replace);

graph
	bar (mean) nat_pos islam_pos if is_party == 1 & reg_party == 0,
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	bar(2, fcolor(black) lcolor(none))
	yscale(off)
	legend(off)
	ylabel(0(.1).8)
	title(Islamists (national), size(3.5))
	name(is_nat, replace);

graph
	bar (mean) nat_pos islam_pos if is_party == 1 & reg_party == 1,
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	bar(2, fcolor(black) lcolor(none))
	yscale(off)
	legend(off)
	ylabel(0(.1).8)
	title(Islamists (regional), size(3.5))
	name(is_reg, replace);

graph combine
	md_nat is_nat is_reg,
	`gph_combine_opts' 	rows(1) name(reg_party, replace)
	title("% of poster campaigns with Nationalist (grey) & Islamic (black) appeals", size(4))
	subtitle("Over national and regional parties in Aceh", size(3));

graph export "figures/fig_7.pdf", as(pdf) replace;
restore;

/**************************************************************************************************/

/*             APPENDIX APPENDIX APPENDIX APPENDIX APPENDIX APPENDIX APPENDIX APPENDIX           */

/**************************************************************************************************/




/**************************************************************************************************/
/* Figure A1.	DPR-RI Candidates reside in Jakarta or their constituency */
/**************************************************************************************************/

preserve;
drop if prov_no == 3100; // excludes candidates competing in Jakarta
gen con_b = .;
replace con_b = 0 if con == "Jakarta";
replace con_b = 1 if con == "Own constituency";

graph
	bar (mean) nat_pos,
	over(con_b, relabel(1 "Jak." 2 "Own Con.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1)1)
	title(All Candidates, size(3.5))
	name(con_all_nat, replace);

graph
	bar (mean)
	islam_pos,
	over(con_b, relabel(1 "Jak." 2 "Own Con.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1)1)
	title(All Candidates, size(3.5))
	name(con_all_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 0,
	over(con_b, relabel(1 "Jak." 2 "Own Con.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1)1)
	title(Muslim Democrats, size(3.5))
	name(con_md_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 0,
	over(con_b, relabel(1 "Jak." 2 "Own Con.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1)1)
	title(Muslim Democrats, size(3.5))
	name(con_md_is, replace);

graph
	bar (mean)
	nat_pos if is_party == 1,
	over(con_b, relabel(1 "Jak." 2 "Own Con.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1)1)
	title(Islamists, size(3.5))
	name(con_is_nat, replace);

graph
	bar (mean)
	islam_pos if is_party == 1,
	over(con_b, relabel(1 "Jak." 2 "Own Con.") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1)1)
	title(Islamists, size(3.5))
	name(con_is_is, replace);

graph combine
	con_all_nat con_all_is con_md_nat con_md_is con_is_nat con_is_is,
	`gph_combine_opts' 	rows(1) name(con_bar, replace)
	title("% of candidates poster campaigns with Nationalist (grey) & Islamic (black) appeals", size(3.5))
	subtitle("Over their residence (Jakarta or their own constituency)", size(3));

graph export "figures/fig_a1.pdf", as(pdf) replace;

restore;

/**************************************************************************************************/
/* Figure A2	Nationalist and Islamic appeals by district (sub-provincial), provincial, & national constituencies */
/**************************************************************************************************/

gen election_b = .;
replace election_b = 1 if election == "leg_dis";
replace election_b = 2 if election == "leg_pro";
replace election_b = 3 if election == "leg_lowerh";

graph
	bar (mean) nat_pos,
	over(election_b, relabel(1 "Dis" 2 "Pro" 3 "Nat") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).7)
	title(All Candidates, size(3.5))
	name(dpn_all_nat, replace);

graph
	bar (mean) islam_pos,
	over(election_b, relabel(1 "Dis" 2 "Pro" 3 "Nat") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).7)
	title(All Candidates, size(3.5))
	name(dpn_all_is, replace);

graph
	bar (mean) nat_pos if is_party == 0,
	over(election_b, relabel(1 "Dis" 2 "Pro" 3 "Nat") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).7)
	title(Muslim Democrats, size(3.5))
	name(dpn_md_nat, replace);

graph
	bar (mean) islam_pos if is_party == 0,
	over(election_b, relabel(1 "Dis" 2 "Pro" 3 "Nat") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).7)
	title(Muslim Democrats, size(3.5))
	name(dpn_md_is, replace);

graph
	bar (mean) nat_pos if is_party == 1,
	over(election_b, relabel(1 "Dis" 2 "Pro" 3 "Nat") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(gray) lcolor(none))
	yscale(off)
	ylabel(0(.1).7)
	title(Islamists, size(3.5))
	name(dpn_is_nat, replace);

graph
	bar (mean) islam_pos if is_party == 1,
	over(election_b, relabel(1 "Dis" 2 "Pro" 3 "Nat") label(labsize(small)))
	blabel(bar, format(%3.2f))
	bar(1, fcolor(black) lcolor(none))
	yscale(off)
	ylabel(0(.1).7)
	title(Islamists, size(3.5))
	name(dpn_is_is, replace);

graph combine
	dpn_all_nat dpn_all_is dpn_md_nat dpn_md_is dpn_is_nat dpn_is_is,
	`gph_combine_opts' 	rows(1) name(dpn_bar, replace)
	title("% of candidates poster campaigns with Nationalist (grey) & Islamic (black) appeals", size(3.5))
	subtitle("Over legislative level (District, Provincial, National)", size(3));

graph export "figures/fig_a2.pdf", as(pdf) replace;



/**************************************************************************************************/
/* Table A1 is created in the an_pos.do file
   Table A2 is created in the an_pos.do file */
/**************************************************************************************************/

/**************************************************************************************************/
/* Table A3	Summary statistics for DVs (UOA = candidate) */
/**************************************************************************************************/

sum nat_pos islam_pos, separator(0);
estpost summarize nat_pos islam_pos;
esttab using "tables/table_a3.csv",
	cells("count(fmt(0)) mean(fmt(3)) sd(fmt(3)) min(fmt(0)) max(fmt(0))")
	noobs nonumber label title(Summary statistics for dependent variables (UOA = Candidate)) replace;
eststo clear;

/**************************************************************************************************/
/* Table A4	Summary statistics for IVs (UOA = candidate) */
/**************************************************************************************************/

sum is_party `ivars' `cvars', separator(0);
estpost summarize is_party `ivars' `cvars';
esttab using "tables/table_a4.csv",
	cells("count(fmt(0)) mean(fmt(3)) sd(fmt(3)) min(fmt(2)) max(fmt(2))")
	noobs nonumber label title(Summary statistics for independent variables (UOA = Candidate)) replace;
eststo clear;

/**************************************************************************************************/
/* Table A5	Correlation matrix for IVs (UOA = candidate) */
/**************************************************************************************************/

corr is_party `ivars' `cvars';
estpost corr is_party `ivars' `cvars', matrix;
esttab using "tables/table_a5.csv",
  cells(rho(fmt(3)))
  not unstack compress noobs nonumber label title(Correlation matrix for independent variables (UOA = Candidate)) replace;


/**************************************************************************************************/
/* Table A6	Candidate Poster Campaigns (OLS)- Main Regression Table */
/**************************************************************************************************/

reg nat_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt' title(OLS Model) replace;
reg nat_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a6, `otreg_opt';
reg nat_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a6, `otreg_opt';
reg islam_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt';
reg islam_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a6, `otreg_opt';
reg islam_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a6, `otreg_opt' excel;
erase tables/table_a6.txt;


/**************************************************************************************************/
/* Table A7	Candidate poster campaigns (TOBIT) (UOA = candidate) */
/**************************************************************************************************/
/* Infor on tobit here: https://stats.idre.ucla.edu/stata/dae/tobit-analysis/ */

tobit nat_pos is_party `ivars' `cvars', ll(0) ul(1);
outreg2 using tables/table_a7, `otreg_opt' title(Tobit Model) replace;
tobit nat_pos `ivars'  `cvars' if is_party == 0, ll(0) ul(1);
outreg2 using tables/table_a7, `otreg_opt';
tobit nat_pos `ivars'  `cvars' if is_party == 1, ll(0) ul(1);
outreg2 using tables/table_a7, `otreg_opt';
tobit islam_pos is_party `ivars' `cvars', ll(0) ul(100);
outreg2 using tables/table_a7, `otreg_opt';
tobit islam_pos `ivars'  `cvars' if is_party == 0, ll(0) ul(1);
outreg2 using tables/table_a7, `otreg_opt';
tobit islam_pos `ivars'  `cvars' if is_party == 1, ll(0) ul(1);
outreg2 using tables/table_a7, `otreg_opt' excel;
erase tables/table_a7.txt;

/**************************************************************************************************/
/* Table A8	Candidate poster campaigns (LOGIT) (UOA = candidate) */
/**************************************************************************************************/

/* 1 if nationalist (or islamic) appeals are in 50% or more of a candidate's posters, else 0 */
gen nat_pos_b = (nat_pos >= 0.5);
gen islam_pos_b = (islam_pos >= 0.5);
label variable nat_pos_b "Nationalist poster campaign (1/0)";
label variable islam_pos_b "Islamist poster campaign (1/0)";

logit nat_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a8, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2)
title(Logit Model: DV = 1 if Nationalist or Islamic appeals are 50% or more of posters) replace;
logit nat_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a8, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit nat_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a8, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit islam_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a8, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit islam_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a8, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit islam_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a8, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2) excel;
erase tables/table_a8.txt;

/**************************************************************************************************/
/* Table A9	Candidate poster campaigns (OLS) (PKS candidates only) */
/**************************************************************************************************/

reg nat_pos `ivars'  `cvars' if party == 38, robust;
outreg2 using tables/table_a9, `otreg_opt' title(OLS Model: PKS Only) replace;
reg islam_pos `ivars'  `cvars' if party == 38, robust;
outreg2 using tables/table_a9, `otreg_opt' excel;
erase tables/table_a9.txt;

/**************************************************************************************************/
/* Table A10	Candidate poster campaigns (OLS) (excludes posters with female candidates) */
/**************************************************************************************************/

preserve;
drop if female_can == 1;
reg nat_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt' title(OLS Model) replace;
reg nat_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a10, `otreg_opt';
reg nat_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a10, `otreg_opt';
reg islam_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt';
reg islam_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a10, `otreg_opt';
reg islam_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a10, `otreg_opt' excel;
erase tables/table_a10.txt;
restore;

/**************************************************************************************************/
/* Table A11 Candidate poster campaigns (OLS) (excludes posters with nat. and Islamic appeals) */
/**************************************************************************************************/

clear;
use "dta/db_can_excl.dta";

/* Regression Macros -----------------------------------------------------------------------------*/
local otreg_opt
	bdec(3) sdec(3) rdec(2) symbol(**, *, ^) label;

/* Vars Macros ------------------------------------------------------------------------------------*/

local ivars
	muslim_pop modern_grdp_pct reg_leg;

local cvars
  female_can java jakarta;

reg nat_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt' title(OLS Model. Excludes posters with both nationalist and Islamic appeals) replace;
reg nat_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a11, `otreg_opt';
reg nat_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a11, `otreg_opt';
reg islam_pos is_party `ivars' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt';
reg islam_pos `ivars'  `cvars' if is_party == 0, robust;
outreg2 using tables/table_a11, `otreg_opt';
reg islam_pos `ivars'  `cvars' if is_party == 1, robust;
outreg2 using tables/table_a11, `otreg_opt' excel;
erase tables/table_a11.txt;


/* END *********************************************************************************************/
